home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 December / 2004-12 CHIP.iso / Narzedzia systemowe / Inno Setup 5.0.4 Beta / isetup-5.0.4-beta.exe / {app} / Examples / CodeDlg.iss (.txt) < prev    next >
Encoding:
Inno Setup Script  |  2004-07-05  |  7.3 KB  |  167 lines

  1. ; -- CodeDlg.iss --
  2. ; This script shows how to insert custom wizard pages into Setup and how to handle
  3. ; these pages. Furthermore it shows how to 'communicate' between the [Code] section
  4. ; and the regular Inno Setup sections using {code:...} constants. Finally it shows
  5. ; how to customize the settings text on the 'Ready To Install' page.
  6. [Setup]
  7. AppName=My Program
  8. AppVerName=My Program version 1.5
  9. DefaultDirName={pf}\My Program
  10. DisableProgramGroupPage=yes
  11. UninstallDisplayIcon={app}\MyProg.exe
  12. [Files]
  13. Source: "MyProg.exe"; DestDir: "{app}"
  14. Source: "MyProg.hlp"; DestDir: "{app}"
  15. Source: "Readme.txt"; DestDir: "{app}"; Flags: isreadme
  16. [Registry]
  17. Root: HKCU; Subkey: "Software\My Company"; Flags: uninsdeletekeyifempty
  18. Root: HKCU; Subkey: "Software\My Company\My Program"; Flags: uninsdeletekey
  19. Root: HKCU; Subkey: "Software\My Company\My Program\Settings"; ValueType: string; ValueName: "Name"; ValueData: "{code:GetUser|Name}"
  20. Root: HKCU; Subkey: "Software\My Company\My Program\Settings"; ValueType: string; ValueName: "Company"; ValueData: "{code:GetUser|Company}"
  21. Root: HKCU; Subkey: "Software\My Company\My Program\Settings"; ValueType: string; ValueName: "DataDir"; ValueData: "{code:GetDataDir}"
  22. ; etc.
  23. [Dirs]
  24. Name: {code:GetDataDir}; Flags: uninsneveruninstall
  25. [Code]
  26.   UserPage: TInputQueryWizardPage;
  27.   UsagePage: TInputOptionWizardPage;
  28.   LightMsgPage: TOutputMsgWizardPage;
  29.   KeyPage: TInputQueryWizardPage;
  30.   ProgressPage: TOutputProgressWizardPage;
  31.   DataDirPage: TInputDirWizardPage;
  32. procedure InitializeWizard;
  33. begin
  34.   { Create the pages }
  35.   UserPage := CreateInputQueryPage(wpWelcome,
  36.     'Personal Information', 'Who are you?',
  37.     'Please specify your name and the company for whom you work, then click Next.');
  38.   UserPage.Add('Name:', False);
  39.   UserPage.Add('Company:', False);
  40.   UsagePage := CreateInputOptionPage(UserPage.ID,
  41.     'Personal Information', 'How will you use My Program?',
  42.     'Please specify how you would like to use My Program, then click Next.',
  43.     True, False);
  44.   UsagePage.Add('Light mode (no ads, limited functionality)');
  45.   UsagePage.Add('Sponsored mode (with ads, full functionality)');
  46.   UsagePage.Add('Paid mode (no ads, full functionality)');
  47.   LightMsgPage := CreateOutputMsgPage(UsagePage.ID,
  48.     'Personal Information', 'How will you use My Program?',
  49.     'Note: to enjoy all features My Program can offer and to support its development, ' +
  50.     'you can switch to sponsored or paid mode at any time by selecting ''Usage Mode'' ' +
  51.     'in the ''Help'' menu of My Program after the installation has completed.'#13#13 +
  52.     'Click Back if you want to change your usage mode setting now, or click Next to ' +
  53.     'continue with the installation.');
  54.   KeyPage := CreateInputQueryPage(UsagePage.ID,
  55.     'Personal Information', 'What''s your registration key?',
  56.     'Please specify your registration key and click Next to continue. If you don''t ' +
  57.     'have a valid registration key, click Back to choose a different usage mode.');
  58.   KeyPage.Add('Registration key:', False);
  59.   ProgressPage := CreateOutputProgressPage('Personal Information',
  60.     'What''s your registration key?');
  61.   DataDirPage := CreateInputDirPage(wpSelectDir,
  62.     'Select Personal Data Directory', 'Where should personal data files be installed?',
  63.     'Select the folder in which Setup should install personal data files, then click Next.',
  64.     False, '');
  65.   DataDirPage.Add('');
  66.   { Set default values, using settings that were stored last time if possible }
  67.   UserPage.Values[0] := GetPreviousData('Name', ExpandConstant('{sysuserinfoname}'));
  68.   UserPage.Values[1] := GetPreviousData('Company', ExpandConstant('{sysuserinfoorg}'));
  69.   case GetPreviousData('UsageMode', '') of
  70.     'light': UsagePage.SelectedValueIndex := 0;
  71.     'sponsored': UsagePage.SelectedValueIndex := 1;
  72.     'paid': UsagePage.SelectedValueIndex := 2;
  73.   else
  74.     UsagePage.SelectedValueIndex := 1;
  75.   end;
  76.   DataDirPage.Values[0] := GetPreviousData('DataDir', '');
  77. procedure RegisterPreviousData(PreviousDataKey: Integer);
  78.   UsageMode: String;
  79. begin
  80.   { Store the settings so we can restore them next time }
  81.   SetPreviousData(PreviousDataKey, 'Name', UserPage.Values[0]);
  82.   SetPreviousData(PreviousDataKey, 'Company', UserPage.Values[1]);
  83.   case UsagePage.SelectedValueIndex of
  84.     0: UsageMode := 'light';
  85.     1: UsageMode := 'sponsored';
  86.     2: UsageMode := 'paid';
  87.   end;
  88.   SetPreviousData(PreviousDataKey, 'UsageMode', UsageMode);
  89.   SetPreviousData(PreviousDataKey, 'DataDir', DataDirPage.Values[0]);
  90. function ShouldSkipPage(PageID: Integer): Boolean;
  91. begin
  92.   { Skip pages that shouldn't be shown }
  93.   if (PageID = LightMsgPage.ID) and (UsagePage.SelectedValueIndex <> 0) then
  94.     Result := True
  95.   else if (PageID = KeyPage.ID) and (UsagePage.SelectedValueIndex <> 2) then
  96.     Result := True
  97.   else
  98.     Result := False;
  99. function NextButtonClick(CurPageID: Integer): Boolean;
  100.   I: Integer;
  101. begin
  102.   { Validate certain pages before allowing the user to proceed }
  103.   if CurPageID = UserPage.ID then begin
  104.     if UserPage.Values[0] = '' then begin
  105.       MsgBox('You must enter your name.', mbError, MB_OK);
  106.       Result := False;
  107.     end else begin
  108.       if DataDirPage.Values[0] = '' then
  109.         DataDirPage.Values[0] := 'C:\' + UserPage.Values[0];
  110.       Result := True;
  111.     end;
  112.   end else if CurPageID = KeyPage.ID then begin
  113.     { Just to show how 'OutputProgress' pages work.
  114.       Always use a try..finally between the Show and Hide calls as shown below. }
  115.     ProgressPage.SetText('Authorizing registration key...', '');
  116.     ProgressPage.SetProgress(0, 0);
  117.     ProgressPage.Show;
  118.     try
  119.       for I := 0 to 10 do begin
  120.         ProgressPage.SetProgress(I, 10);
  121.         Sleep(100);
  122.       end;
  123.     finally
  124.       ProgressPage.Hide;
  125.     end;
  126.     if KeyPage.Values[0] = 'inno' then
  127.       Result := True
  128.     else begin
  129.       MsgBox('You must enter a valid registration key. (Hint: The key is "inno".)', mbError, MB_OK);
  130.       Result := False;
  131.     end;
  132.   end else
  133.     Result := True;
  134. function UpdateReadyMemo(Space, NewLine, MemoUserInfoInfo, MemoDirInfo, MemoTypeInfo,
  135.   MemoComponentsInfo, MemoGroupInfo, MemoTasksInfo: String): String;
  136.   S: String;
  137. begin
  138.   { Fill the 'Ready Memo' with the normal settings and the custom settings }
  139.   S := '';
  140.   S := S + 'Personal Information:' + NewLine;
  141.   S := S + Space + UserPage.Values[0] + NewLine;
  142.   if UserPage.Values[1] <> '' then
  143.     S := S + Space + UserPage.Values[1] + NewLine;
  144.   S := S + NewLine;
  145.   S := S + 'Usage Mode:' + NewLine + Space;
  146.   case UsagePage.SelectedValueIndex of
  147.     0: S := S + 'Light mode';
  148.     1: S := S + 'Sponsored mode';
  149.     2: S := S + 'Paid mode';
  150.   end;
  151.   S := S + NewLine + NewLine;
  152.   S := S + MemoDirInfo + NewLine;
  153.   S := S + Space + DataDirPage.Values[0] + ' (personal data files)' + NewLine;
  154.   Result := S;
  155. function GetUser(Param: String): String;
  156. begin
  157.   { Return a user value }
  158.   { Could also be split into separate GetUserName and GetUserCompany functions }
  159.   if Param = 'Name' then
  160.     Result := UserPage.Values[0]
  161.   else if Param = 'Company' then
  162.     Result := UserPage.Values[1];
  163. function GetDataDir(Param: String): String;
  164. begin
  165.   { Return the selected DataDir }
  166.   Result := DataDirPage.Values[0];
  167.